package com.zwj.api.client.fallback;

import com.hmall.common.utils.CollUtils;
import com.zwj.api.client.ItemClient;
import com.zwj.api.dto.ItemDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.util.Collection;
import java.util.List;

/**
 * 商品服务Client 降级逻辑
 *
 * @author 张文接
 * @version 1.0
 * @createTime 2024/8/3 13:39
 */
@Slf4j
public class ItemClientFallback implements FallbackFactory<ItemClient> {
    @Override
    public ItemClient create(Throwable cause) {
        return new ItemClient() {
            /**
             * 查询商品信息降级逻辑
             * @param ids 商品id集合
             * @return 商品实体
             */
            @Override
            public List<ItemDTO> queryItemByIds(Collection<Long> ids) {
                log.error("远程调用ItemClient#queryItemByIds方法出现异常,参数：{}", ids, cause);
                return CollUtils.emptyList();
            }
        };
    }
}
